﻿using _12306helper.Common;
using _12306helper.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace _12306helper.Service
{
    public class TrainService
    {
        public static List<string> StationAutoComplete(string input)
        {
            List<string> result = new List<string>();
            List<Station> stations = CommonUtil.Stations;
            Regex reg = new Regex("^[a-zA-Z]+$");
            if (reg.IsMatch(input))
            {
                foreach (Station s in stations)
                {
                    if (s.ShortName.Contains(input))
                    {
                        result.Add(s.Name);
                    }
                    else if (s.ShortName1.Contains(input))
                    {
                        result.Add(s.Name);
                    }
                    else if (s.FullName.Contains(input))
                    {
                        result.Add(s.Name);
                    }
                }
            }
            else
            {
                foreach (Station s in stations)
                {
                    if (s.Name.Contains(input))
                    {
                        result.Add(s.Name);
                    }
                }
            }
            return result;
        }
    }
}
